let MovieTags = [{
  id: 1,
  name: '剧情'
}, {
  id: 2,
  name: '喜剧'
}, {
  id: 3,
  name: '都市'
}]

function add(tag) {
  const r = JSON.parse(JSON.stringify(tag))
  r.id = MovieTags[MovieTags.length - 1].id + 1
  MovieTags.push(r)
}

function list(name) {
  const mocks = MovieTags.filter(item => {
    return !(name && (!item.name || item.name.indexOf(name) === -1))
  })
  return { success: true, data: mocks }
}

function deleteRecord(id) {
  id = id ? parseInt(id) : null
  if (id) {
    MovieTags = MovieTags.filter(item => item.id !== id)
  }
}

module.exports = { list, add, deleteRecord, MovieTags }
